package com.fake.path.adapter;

import java.io.IOException;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;

import com.fake.commonsware.cwac.adapter.AdapterWrapper;
import com.fakepath.items.Moment;
import com.fakepath.items.Response;
import com.fakepath.task.AppendFeedTask;

public abstract class PathAdapter extends AdapterWrapper {
	private Activity activity;
	private boolean busyFetching;
	private View.OnClickListener forceRefreshClickListener;
	private boolean reachedEndOfFeed;
	private boolean thereWasAnException;

	public PathAdapter(Activity activity, ListAdapter wrapped) {
		super(wrapped);
		this.activity = activity;
		this.forceRefreshClickListener = new View.OnClickListener() {
			public void onClick(View paramView) {
				PathAdapter.this.clearErrors();
				PathAdapter.this.forceRefresh();
			}
		};
	}

	public abstract void forceRefresh();

	protected void clearErrors() {
		this.thereWasAnException = false;
	}

	public final void appendMoreContent() {
		// this.busyFetching = true;
		// new AppendFeedTask() {
		// public Response call() throws Exception {
		// return PathAdapter.this
		// .getFeedContentOlderThanLastMoment();
		// }
		// }.execute();
	}

	public final void fetchInitialContent() {
		// this.busyFetching = true;
		// new AppendFeedTask()
		// {
		// public Response call()
		// throws Exception
		// {
		// return FeedFetchingAdapter.this.getInitialFeedContent();
		// }
		// }
		// .execute();
	}

	public boolean fetchingContent() {
		return this.busyFetching;
	}

	public abstract Response getFeedContentOlderThanLastMoment()
			throws IOException;

	public abstract Response getInitialFeedContent() throws IOException;

	public abstract void appendMoments(Response paramResponse);

	public abstract Moment getLastMoment();

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		return super.getView(position, convertView, parent);
	}
}
